package com.example.task1.ui.base;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.bean.CommentBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class NewsDetailsAdapter extends BaseAdapter<CommentBean.RowsDTO> {
    private TextView userName;
    private TextView userRead;
    private TextView content;
    private List<CommentBean.RowsDTO> mData = new ArrayList<>();

    public void setData(List<CommentBean.RowsDTO> data) {
        int size = mData.size();
        mData.addAll(data);
        notifyItemInserted(size);
    }

    public void addData(CommentBean.RowsDTO data) {
        mData.add(0,data);
        notifyItemRangeChanged(0,1);
    }

    @Override
    protected int getLayout() {
        return R.layout.basecommentlyout;
    }

    @Override
    protected Context getContext() {
        return null;
    }

    @Override
    public List<CommentBean.RowsDTO> getData() {
        return mData;
    }

    @Override
    protected void onBind(myHolder holder, CommentBean.RowsDTO date) {
        userName.setText(date.getUserName());
        userRead.setText(date.getLikeNum() + "人赞");
        content.setText(date.getContent());
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public int getItemViewType(int position) {
        return position;
    }

    private void initView(View itemView) {
        userName = (TextView) itemView.findViewById(R.id.user_name);
        userRead = (TextView) itemView.findViewById(R.id.user_read);
        content = (TextView) itemView.findViewById(R.id.content);
    }
}
